#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
 
using namespace std;
 
int main() {
    vector<int> primes;
    for (int i = 100; i < 1000; ++i) {
        bool isPrime = true;
        for (int a = 2; a <= i / 2; ++a) {
            if (i % a == 0) {
                isPrime = false;
                break;
            }
        }
        if (isPrime) {
            primes.push_back(i);
        }
    }
 
    vector<string> digitWords = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
 
    string input;
    getline(cin, input);
 
    istringstream iss(input);
    vector<string> tokens;
    string word;
    while (iss >> word) {
        tokens.push_back(word);
    }
 
    if (tokens.size() == 3) {
        string hundreds = tokens[0], tens = tokens[1], ones = tokens[2];
        if (find(digitWords.begin(), digitWords.end(), hundreds) != digitWords.end() &&
            find(digitWords.begin(), digitWords.end(), tens) != digitWords.end() &&
            find(digitWords.begin(), digitWords.end(), ones) != digitWords.end()) {
 
            if (hundreds == "zero") {
                cout << "трехзначное не начинается с нуля!" << endl;
            } else {
                int number = (find(digitWords.begin(), digitWords.end(), hundreds) - digitWords.begin()) * 100 +
                             (find(digitWords.begin(), digitWords.end(), tens) - digitWords.begin()) * 10 +
                             (find(digitWords.begin(), digitWords.end(), ones) - digitWords.begin());
 
                int maxLessOrEqual = 0;
                int minGreaterOrEqual = 10000;
 
                for (int prime : primes) {
                    if (prime <= number) {
                        maxLessOrEqual = prime;
                    }
                    if (prime >= number && minGreaterOrEqual == 10000) {
                        minGreaterOrEqual = prime;
                    }
                }
 
                cout << minGreaterOrEqual << " " << number << " " << maxLessOrEqual << endl;
                if (number - maxLessOrEqual > minGreaterOrEqual - number) {
                    cout << minGreaterOrEqual << endl;
                } else {
                    cout << maxLessOrEqual << endl;
                }
            }
        } else {
            cout << "Wrong." << endl;
        }
    } else {
        cout << "Wrong." << endl;
    }
 
    return 0;
}